﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NET.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NET.List
{
    [TestClass]
    public class Main
    {
        [TestMethod]
        public void ListTest()
        {
            List<People> list = People.GetList();

            Console.WriteLine($"list:{list.ToJson()}");
        }


        [TestMethod]
        public void LambdaForEachTest()
        {
            var list = People.GetList();
            list.ForEach(item => item.Age++);

            Console.WriteLine($"list:{list.ToJson()}");
        }

        [TestMethod]
        public void LambdaWhereTest()
        {
            var list = People.GetList();
            var result = list.Where(item => item.Age>20);

            Console.WriteLine($"result:{result.ToJson()}");
        }


        [TestMethod]
        public void LambdaFindTest()
        {
            var list = People.GetList();
            var result = list.Find(item => item.Name.Contains("张"));

            Console.WriteLine($"result:{result.ToJson()}");
        }


        [TestMethod]
        public void LambdaFindAllTest()
        {
            var list = People.GetList();
            var result = list.FindAll(item => item.Name.Contains("张"));

            Console.WriteLine($"result:{result.ToJson()}");
        }

        [TestMethod]
        public void LambdaSelectTest()
        {
            var list = People.GetList();
            var result = list.Select(item => item.Name);

            Console.WriteLine($"result:{result.ToJson()}");
        }

        [TestMethod]
        public void LambdaDicTest()
        {
            var dic = new Dictionary<string, People>();
            var list = People.GetList();
            list.ForEach(item =>
            {
                dic.Add(item.Name, item);
            });
            Console.WriteLine($"result:{dic.ToJson()}");
        }
    }
}
